<?php

namespace Apps\AppApi\Method\User;


use Apps\AppApi\Method\BaseMethod;
use Apps\Common\Models\BpFavorites;

/**
 * 关注美容院
 * @author      545
 * @date        2016年1月12日
 * @version     1.1.2
 * @copyright   Copyright 2015 meelier.com
 */
class Favorites extends BaseMethod
{
    public function run()
    {
    	if(false == $this->verifyUserAuth()){
    		return false;
    	}
    	$bp_id = $this->getDataItem('bp_id',0);
    	$userId = $this->getUserAuth()->userId;
    	//$userId=1;
    	$info=BpFavorites::findFirst("bp_id = $bp_id and user_id = $userId");
    	if($info->id!=''){
    		return $this->setResult(['success'=>0,'message'=>'已关注！']);
    	}
    	$model=new BpFavorites();
    	$model->user_id=$userId;
    	$model->bp_id=$bp_id;
    	$status=$model->save();
    	$num=BpFavorites::count([
    			'conditions' => "bp_id = $bp_id",
    			]);
    	if($status){
    		$this->setResult(['success'=>1,'message'=>'关注成功！','favorite_num'=>$num]);
    	}else{
    		$this->setResult(['success'=>0,'message'=>'关注失败！']);
    	}
    }
}